package com.yzh.lambda;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Stream;

/**
 * @author 于振晗
 * @title: LambdaTest01
 * @description: TODO 参数
 * @date 2020年09月04日
 * @path com.yzh.lambda
 */
public interface LambdaTest02 {
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        Collections.addAll(list,7,4,5,1,2,3,9,8,6,222);
        new LinkedHashSet<>();
        Stream<Integer> stream = list.stream();


        System.out.println(list);
        List<Integer> list1;
        //自主封装保留小于8的数
        list1 = retainIf(val->val<8,list);
        System.out.println(list1);



        //删除所有小于8的值
        list.removeIf(val-> val<8 );
        System.out.println(list);

    }


    public static <E> List retainIf(Predicate<E> predicate,List<E> list){
        List<E> list1 = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            if(predicate.test(list.get(i))){
                list1.add(list.get(i));
            }
        }
        return list1;
    }
}
